/*
process.stdin.resume();
process.stdin.setEncoding('utf8');

var droid = ['R','P','S'];
var randomValue=Math.floor(droid.length*Math.random())
process.stdout.on('Make your choice [R,P,S]:');

proces.stdin('Droid',function)
console.log('Droid Played :'+droid[randomValue]);



process.stdin.resume();
process.stdin.setEncoding('utf8');
 
process.stdin.on('data', function (chunk) {
 process.stdout.write('data: ' + chunk);
});
*/

function ask(question, format, callback) {
 var stdin = process.stdin, stdout = process.stdout;
 
 stdin.resume();
 stdout.write(question + ": ");
 
 stdin.once('data', function(data) {
   data = data.toString().trim();
 
   if (format.test(data)) {
     callback(data);
   } else {
     stdout.write("It should match: "+ format +"\n");
     ask(question, format, callback);
   }
 });
}

ask("Make your choice : [R,P,S]", /.+/, function(name) {
  ask("Droid has played : ", /^.+@.+$/, function(email) {
    console.log("Your name is: ", name);
    console.log("Your email is:", email);
 
    process.exit();
  });
});